package com.xrr.shardingdemo.config;

import com.xrr.shardingdemo.mapper.CommonMapper;
import com.xrr.shardingdemo.sharding.ShardingAlgorithmTool;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Order(value = 1) // 数字越小 越先执行
@Component
public class ShardingTableLoadRunner implements CommandLineRunner {

    @Resource
    private CommonMapper commonMapper;

    @Override
    public void run(String... args) throws Exception {
        // 给 分表工具类注入属性
        ShardingAlgorithmTool.setCommonMapper(commonMapper);
        // 调用缓存重载方法
        ShardingAlgorithmTool.tableNameCacheReload("demo");

    }
}
